home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / snip0493.zip / MOUSE.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  9KB  |  340 lines

  1. /*
  2. ** A series of routines to provide access to MicroSoft (and compatible)
  3. ** mice.  Consult your mouse documentation for detailed information regarding
  4. ** each mouse driver function.
  5. **
  6. ** by Bob Jarvis w/ modifications by Bob Stout
  7. */
  8.  
  9. #include <dos.h>
  10. #include "mouse.h"
  11.  
  12. int mouse_present = 0;  /* globally visible */
  13.  
  14. /*
  15. ** Uses driver function 0 to initialize the mouse software to its default
  16. ** settings.  If no mouse is present it returns 0.  If a mouse is present, it
  17. ** returns -1, and places the value of the mouse type (2 = MicroSoft,
  18. ** 3 = Mouse Systems, other values are possible) in *mousetype.  Also
  19. ** initializes the global variable mouse_present (0 = no mouse, !0 = mouse
  20. ** is available).
  21. */
  22.  
  23. int ms_reset(int *mousetype)
  24. {
  25.       union REGS workregs;
  26.  
  27.       workregs.x.ax = 0;
  28.       int86(MSMOUSE,&workregs,&workregs);
  29.       *mousetype = workregs.x.bx;
  30.       mouse_present = workregs.x.ax;
  31.       return(mouse_present);
  32. }
  33.  
  34. /*
  35. ** Makes the mouse cursor visible.
  36. */
  37.  
  38. void ms_show_cursor(void)
  39. {
  40.       union REGS workregs;
  41.  
  42.       workregs.x.ax = 1;
  43.       int86(MSMOUSE,&workregs,&workregs);
  44. }
  45.  
  46. /*
  47. ** Hides the mouse cursor.  Should be called before changing any portion of
  48. ** the screen under the mouse cursor.
  49. */
  50.  
  51. void ms_hide_cursor(void)
  52. {
  53.       union REGS workregs;
  54.  
  55.       workregs.x.ax = 2;
  56.       int86(MSMOUSE,&workregs,&workregs);
  57. }
  58.  
  59. /*
  60. ** Obtains information about the mouse position and button status.
  61. ** Places the current horizontal and vertical positions in *horizpos and
  62. ** *vertpos, respectively.  Returns the mouse button status, which is
  63. ** mapped at the bit level as follows:
  64. **    Bit 0 - left button    \
  65. **    Bit 1 - right button    >-- 0 = button up, 1 = button down
  66. **    Bit 2 - middle button  /
  67. */
  68.  
  69. int ms_get_mouse_pos(int *horizpos, int *vertpos) /* Returns button status */
  70. {
  71.       union REGS workregs;
  72.  
  73.       workregs.x.ax = 3;
  74.       int86(MSMOUSE,&workregs,&workregs);
  75.       *horizpos = workregs.x.cx;
  76.       *vertpos  = workregs.x.dx;
  77.       return(workregs.x.bx);
  78. }
  79.  
  80. /*
  81. ** Moves the mouse cursor to a new position.
  82. */
  83.  
  84. void ms_set_mouse_pos(int horizpos, int vertpos)
  85. {
  86.       union REGS workregs;
  87.  
  88.       workregs.x.ax = 4;
  89.       workregs.x.cx = horizpos;
  90.       workregs.x.dx = vertpos;
  91.       int86(MSMOUSE,&workregs,&workregs);
  92. }
  93.  
  94. /*
  95. ** Obtains information about the last time the specified button
  96. ** (0 = left, 1 = right, 2 = middle) was pressed.  Returns the current
  97. ** button status (same format as return from ms_get_mouse_pos() above).
  98. */
  99.  
  100. int ms_button_press_status(int  button,
  101.                            int *press_count,
  102.                            int *column,
  103.                            int *row)
  104. {
  105.       union REGS workregs;
  106.  
  107.       workregs.x.ax = 5;
  108.       workregs.x.bx = button;
  109.       int86(MSMOUSE,&workregs,&workregs);
  110.       *press_count = workregs.x.bx;
  111.       *column = workregs.x.cx;
  112.       *row = workregs.x.dx;
  113.       return(workregs.x.ax);
  114. }
  115.  
  116. /*
  117. ** Similar to above but obtains information about the last release of the
  118. ** specified button.
  119. */
  120.  
  121. int ms_button_release_status(int  button,
  122.                              int *release_count,
  123.                              int *column,
  124.                              int *row)
  125. {
  126.       union REGS workregs;
  127.  
  128.       workregs.x.ax = 6;
  129.       workregs.x.bx = button;
  130.       int86(MSMOUSE,&workregs,&workregs);
  131.       *release_count = workregs.x.bx;
  132.       *column = workregs.x.cx;
  133.       *row = workregs.x.dx;
  134.       return(workregs.x.ax);
  135. }
  136.  
  137. /*
  138. ** Forces the mouse cursor to remain within the range specified.
  139. */
  140.  
  141. void ms_restrict_horiz(int min, int max)
  142. {
  143.       union REGS workregs;
  144.  
  145.       workregs.x.ax = 7;
  146.       workregs.x.cx = min;
  147.       workregs.x.dx = max;
  148.       int86(MSMOUSE,&workregs,&workregs);
  149. }
  150.  
  151. /*
  152. ** Forces the mouse cursor to remain within the range specified.
  153. */
  154.  
  155. void ms_restrict_vert(int min, int max)
  156. {
  157.       union REGS workregs;
  158.  
  159.       workregs.x.ax = 8;
  160.       workregs.x.cx = min;
  161.       workregs.x.dx = max;
  162.       int86(MSMOUSE,&workregs,&workregs);
  163. }
  164.  
  165. void ms_define_window(int left, int top, int right, int bottom)
  166. {
  167.       ms_restrict_horiz(left,right);
  168.       ms_restrict_vert(top,bottom);
  169. }
  170.  
  171. /*
  172. ** Allows the user to set the graphics cursor to a new shape.  Check your
  173. ** mouse reference manual for full information about the use of this function.
  174. */
  175.  
  176. void ms_set_graphics_cursor(int      horiz_hotspot,
  177.                             int      vert_hotspot,
  178.                             unsigned seg_shape_tables,
  179.                             unsigned offset_shape_tables)
  180. {
  181.       union REGS workregs;
  182.       struct SREGS segregs;
  183.  
  184.       workregs.x.ax = 9;
  185.       workregs.x.bx = horiz_hotspot;
  186.       workregs.x.cx = vert_hotspot;
  187.       workregs.x.dx = offset_shape_tables;
  188.       segregs.es  = seg_shape_tables;
  189.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  190. }
  191.  
  192. /*
  193. ** Selects either the software or hardware cursor and sets the start and stop
  194. ** scan lines (for the hardware cursor) or the screen and cursor masks (for
  195. ** the software cursor).  Consult your mouse reference for more information.
  196. */
  197.  
  198. void ms_set_text_cursor(int type, int screen_mask, int cursor_mask)
  199. {
  200.       union REGS workregs;
  201.  
  202.       workregs.x.ax = 10;
  203.       workregs.x.bx = type;
  204.       workregs.x.cx = screen_mask;
  205.       workregs.x.dx = cursor_mask;
  206.       int86(MSMOUSE,&workregs,&workregs);
  207. }
  208.  
  209. /*
  210. ** Obtains the horizontal and vertical raw motion counts since the last
  211. ** request.
  212. */
  213.  
  214. void ms_read_motion_counters(int *horiz, int *vert)
  215. {
  216.       union REGS workregs;
  217.  
  218.       workregs.x.ax = 11;
  219.       int86(MSMOUSE,&workregs,&workregs);
  220.       *horiz = workregs.x.cx;
  221.       *vert  = workregs.x.dx;
  222. }
  223.  
  224. /*
  225. ** Sets up a subroutine to be called when a given event occurs.
  226. ** NOTE: Use with extreme care.  The function whose address is provided MUST
  227. **    terminate with a far return (i.e. must be compiled using large model).
  228. **    Also, no DOS or BIOS services may be used, as the user-defined function
  229. **    is (in effect) an extension to an interrupt service routine.
  230. */
  231.  
  232. void ms_set_event_subroutine(int      mask,
  233.                              unsigned seg_routine,
  234.                              unsigned offset_routine)
  235. {
  236.       union REGS workregs;
  237.       struct SREGS segregs;
  238.  
  239.       workregs.x.ax = 12;
  240.       workregs.x.cx = mask;
  241.       workregs.x.dx = offset_routine;
  242.       segregs.es  = seg_routine;
  243.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  244. }
  245.  
  246. /*
  247. ** Turns light pen emulation mode on.
  248. */
  249.  
  250. void ms_light_pen_on(void)
  251. {
  252.       union REGS workregs;
  253.  
  254.       workregs.x.ax = 13;
  255.       int86(MSMOUSE,&workregs,&workregs);
  256. }
  257.  
  258. /*
  259. ** turns light pen emulation mode off.
  260. */
  261.  
  262. void ms_light_pen_off(void)
  263. {
  264.       union REGS workregs;
  265.  
  266.       workregs.x.ax = 14;
  267.       int86(MSMOUSE,&workregs,&workregs);
  268. }
  269.  
  270. /*
  271. ** Sets the sensitivity of the mouse.  Defaults are 8 and 16 for horizontal
  272. ** and vertical sensitivity (respectively).
  273. */
  274.  
  275. void ms_set_sensitivity(int horiz, int vert)
  276. {
  277.       union REGS workregs;
  278.  
  279.       workregs.x.ax = 15;
  280.       workregs.x.cx = horiz;
  281.       workregs.x.dx = vert;
  282.       int86(MSMOUSE,&workregs,&workregs);
  283. }
  284.  
  285. /*
  286. ** Sets up a region of the screen inside of which the mouse cursor will
  287. ** automatically be 'hidden'.
  288. */
  289.  
  290. void ms_protect_area(int left, int top, int right, int bottom)
  291. {
  292.       union REGS workregs;
  293.  
  294.       workregs.x.ax = 16;
  295.       workregs.x.cx = left;
  296.       workregs.x.dx = top;
  297.       workregs.x.si = right;
  298.       workregs.x.di = bottom;
  299.       int86(MSMOUSE,&workregs,&workregs);
  300. }
  301.  
  302. /*
  303. * Similar to ms_set_graphics_cursor() but allows a larger cursor.  Consult
  304. ** your mouse documentation for information on how to use this function.
  305. */
  306.  
  307. int ms_set_large_graphics_cursor(int      width,
  308.                                  int      height,
  309.                                  int      horiz_hotspot,
  310.                                  int      vert_hotspot,
  311.                                  unsigned seg_shape_tables,
  312.                                  unsigned offset_shape_tables)
  313. {
  314.       union REGS workregs;
  315.       struct SREGS segregs;
  316.  
  317.       workregs.x.ax = 18;
  318.       workregs.x.bx = (width << 8) + horiz_hotspot;
  319.       workregs.x.cx = (height << 8) + vert_hotspot;
  320.       workregs.x.dx = offset_shape_tables;
  321.       segregs.es  = seg_shape_tables;
  322.       int86x(MSMOUSE,&workregs,&workregs,&segregs);
  323.       if(workregs.x.ax == -1)
  324.             return(workregs.x.ax); /* Return -1 if function 18 supported */
  325.       else  return(0);             /* else return 0                      */
  326. }
  327.  
  328. /*
  329. ** Sets the threshold value for doubling cursor motion.  Default value is 64.
  330. */
  331.  
  332. void ms_set_doublespeed_threshold(int speed)
  333. {
  334.       union REGS workregs;
  335.  
  336.       workregs.x.ax = 19;
  337.       workregs.x.dx = speed;
  338.       int86(MSMOUSE,&workregs,&workregs);
  339. }
  340.